﻿namespace Smart.Admin.Domain.Model.Response
{
    public class JsonResponse<T> : BaseResponse
    {
        public T data { get; set; }//数据
    }


    public class JsonResponse : BaseResponse
    {
        public object data { get; set; }//数据
    }


    public class BaseResponse
    {
        public string message { get; set; }//消息


        public string code { get; set; } = "0"; //状态码

        public int total { get; set; }//总条数

        public string returnUrl { get; set; } //跳转地址
    }


    public class JsonResult
    {
        /// <summary>
        /// 执行成功
        /// </summary>
        /// <param name="data"></param>
        /// <param name="code"></param>
        /// <param name="message"></param>
        /// <param name="total"></param>
        /// <param name="returnUrl"></param>
        /// <returns></returns>
        public static JsonResponse Success(string code = "0", string message = "", int total = 0, string returnUrl = "")
        {
            return new JsonResponse { code = code, message = message, total = total, returnUrl = returnUrl };
        }

        /// <summary>
        /// 执行失败
        /// </summary>
        /// <param name="data"></param>
        /// <param name="code"></param>
        /// <param name="message"></param>
        /// <param name="total"></param>
        /// <param name="returnUrl"></param>
        /// <returns></returns>
        public static JsonResponse Error(string code = "-1", string message = "", int total = 0, string returnUrl = "")
        {
            return new JsonResponse { code = code, message = message, total = total, returnUrl = returnUrl };
        }

        /// <summary>
        /// 执行成功
        /// </summary>
        /// <param name="data"></param>
        /// <param name="code"></param>
        /// <param name="message"></param>
        /// <param name="total"></param>
        /// <param name="returnUrl"></param>
        /// <returns></returns>
        public static JsonResponse<T> Success<T>(T data = default, string code = "0", string message = "", int total = 0, string returnUrl = "")
        {
            return new JsonResponse<T> { data = data, code = code, message = message, total = total, returnUrl = returnUrl };
        }

        /// <summary>
        /// 执行失败
        /// </summary>
        /// <param name="data"></param>
        /// <param name="code"></param>
        /// <param name="message"></param>
        /// <param name="total"></param>
        /// <param name="returnUrl"></param>
        /// <returns></returns>
        public static JsonResponse<T> Error<T>(string code = "-1", string message = "", int total = 0, string returnUrl = "")
        {
            return new JsonResponse<T> { code = code, message = message, total = total, returnUrl = returnUrl };
        }
    }
}
